﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using EastFantasy.DnfAccountScan.BLL;
using EastFantasy.DnfAccountScan.Model;
using EastFantasy.DnfAccountScan.Public;
using Winista.Text.HtmlParser;
using Winista.Text.HtmlParser.Lex;
using Winista.Text.HtmlParser.Util;
using EastFantasy.DnfAccountScan.Main.WebService.PublicService;
using SystemLogModel = EastFantasy.DnfAccountScan.Main.WebService.PublicService.SystemLogModel;

namespace EastFantasy.DnfAccountScan.Main
{
    public partial class Main : RibbonForm
    {
        #region Init
        public Main()
        {
            InitializeComponent();
            InitSkinGallery();
        }

        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }

        private void Main_Load(object sender, EventArgs e)
        {
            //默认需要验证码
            IsNeed = true;
            service = new PublicService();
        }

        #endregion

        #region 声明变量

        /// <summary>
        /// WebService
        /// </summary>
        PublicService service;

        /// <summary>
        /// 退出程序
        /// </summary>
        public delegate void CloseAll();

        private string Wait = string.Empty;
        /// <summary>
        /// 退出程序
        /// </summary>
        public CloseAll CloseFather;

        /// <summary>
        /// 隐藏父窗口
        /// </summary>
        public delegate void HideFather();

        /// <summary>
        /// 隐藏父窗口
        /// </summary>
        public HideFather Hides;

        /// 是否检测封号
        /// <summary>
        /// 是否检测封号
        /// </summary>
        private bool IsLeaverBuster { get; set; }

        /// 验证码
        /// <summary>
        /// 验证码
        /// </summary>
        private string ImageCode { get; set; }

        /// 是否需要显示 True:显示 False:不显示
        /// <summary>
        /// 是否需要显示 True:显示 False:不显示
        /// </summary>
        private bool IsNeed { get; set; }

        /// 是否需要重新输入 True:需要 False:不需要
        /// <summary>
        /// 是否需要重新输入 True:需要 False:不需要
        /// </summary>
        private bool ReEnter { get; set; }

        /// 黑信
        /// <summary>
        /// 黑信
        /// </summary>
        private List<Account> ListAccounts;

        /// 服务器地址
        /// <summary>
        /// 服务器地址
        /// </summary>
        private readonly Uri Host = new Uri("http://119.147.14.253:14000");

        /// 扫描账号线程
        /// <summary>
        /// 扫描账号线程
        /// </summary>
        public Thread threadCheckAccount;

        /// 扫描账号索引
        /// <summary>
        /// 扫描账号索引
        /// </summary>
        private int CheckAccountIndex;

        /// 扫描角色线程
        /// <summary>
        /// 扫描角色线程
        /// </summary>
        #endregion

        #region 打开新文件
        /// <summary>
        /// 打开新文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iOpen_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                //清空Grid
                gvAccount.DataSource = null;
                //还原index
                CheckAccountIndex = 0;

                //关闭现有线程
                if (threadCheckAccount != null && threadCheckAccount.IsAlive)
                {
                    threadCheckAccount.Abort();
                    threadCheckAccount = null;
                }
                //恢复索引
                CheckAccountIndex = 0;
                var dialog = new OpenFileDialog { Filter = @"黑信|*.txt" };
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (!string.IsNullOrEmpty(iLevel.EditValue.ToString()))
                    {
                        ListAccounts = ReadFile(dialog.FileName);
                        int lowLevel = int.Parse(iLevel.EditValue.ToString().Substring(0, iLevel.EditValue.ToString().IndexOf('-')));
                        int highLevel = int.Parse(iLevel.EditValue.ToString().Substring(lowLevel.ToString().Length + 1, iLevel.EditValue.ToString().Length - lowLevel.ToString().Length - 1));
                        var accounts = ListAccounts.Where(l => l.Level >= lowLevel && l.Level <= highLevel).ToList();
                        gvAccount.DataSource = accounts;
                    }
                    #region 测试主从表
                    //List<Account> listAccount = new List<Account>();
                    //foreach (DataRow row in dtAccountAll.Rows)
                    //{
                    //    Account account = new Account();
                    //    account.AccountName = row["Account"].ToString();
                    //    account.Server = row["Server"].ToString();
                    //    account.Password = row["Password"].ToString();
                    //    account.Level = int.Parse(row["Level"].ToString());
                    //    account.IP = row["IP"].ToString();
                    //    account.IsRight = row["IsRight"].ToString();
                    //    BindingList<Role> listRole = new BindingList<Role>();
                    //    for (int i = 0; i < 3; i++)
                    //    {
                    //        Role role = new Role();
                    //        role.Account = row["Account"].ToString();
                    //        role.RoleLevel = i;
                    //        role.RoleName = row["Server"].ToString();
                    //        listRole.Add(role);
                    //    }
                    //    account.listRole = listRole;
                    //    listAccount.Add(account);
                    //}
                    #endregion
                }
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "iOpen_ItemClick/打开新文件";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                //service.InsertErrorLog(log);
            }
        }

        #endregion

        #region 读取txt
        /// <summary>
        /// 读取txt
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        private List<Account> ReadFile(string filePath)
        {
            //int i = 0;
            try
            {
                List<Account> listAccounts = new List<Account>();
                //读取文档
                StreamReader reader = new StreamReader(filePath, System.Text.Encoding.Default);
                string line = string.Empty;
                while (line != null)
                {
                    try
                    {
                        Account account = new Account();
                        //i++;
                        line = reader.ReadLine();
                        if (string.IsNullOrEmpty(line)) continue;
                        //去除首尾空格
                        line = line.TrimStart();
                        //将\t替换为空格
                        line = line.Replace("\t", " ");
                        //将ip:替换为空格
                        line = line.Replace("ip:", " ");
                        line = line.Replace("IP:", " ");
                        //第一个空格所在索引
                        int spaceIndex = line.IndexOf(" ", StringComparison.Ordinal);
                        if (spaceIndex > 0)
                        {
                            //大区
                            string server = line.Substring(0, spaceIndex);
                            line = line.Replace(server, string.Empty).TrimStart();
                            spaceIndex = line.IndexOf(" ", StringComparison.Ordinal);
                            if (spaceIndex < 0) continue;
                            //移除所有中文字信息
                            line = PublicClass.RegexString(line, 2);
                            if (spaceIndex > line.Length)
                                continue;
                            //号码
                            string accountName = line.Substring(0, spaceIndex);
                            if (PublicClass.RegexString(accountName, 3).Equals("N"))
                                continue;
                            //判断号码是否已经存在于列表中
                            if (listAccounts.Any(a => a.AccountName.Equals(accountName)))
                                continue;
                            line = line.Remove(0, accountName.Length).TrimStart();
                            spaceIndex = line.IndexOf(" ", StringComparison.Ordinal);
                            if (spaceIndex > line.Length)
                                continue;
                            //密码
                            string password = line.Substring(0, spaceIndex);
                            line = line.Remove(0, password.Length).TrimStart();
                            spaceIndex = line.IndexOf(" ", StringComparison.Ordinal);
                            if (spaceIndex > line.Length)
                                continue;
                            //等级
                            int level = 0;
                            if (spaceIndex >= 0)
                            {
                                if (line.Substring(0, spaceIndex).Length > 0 && line.Substring(0, spaceIndex).Length < 3)
                                {
                                    if (int.TryParse(line.Substring(0, spaceIndex), out level))
                                    {
                                        if (level > 0)
                                            line = line.Replace(level.ToString(CultureInfo.InvariantCulture), string.Empty).TrimStart();
                                    }
                                }
                            }

                            //IP
                            string ip = PublicClass.RegexString(line, 4);
                            if (!ip.Equals(string.Empty))
                                line = line.Replace(ip, string.Empty);
                            account.Server = server;
                            account.AccountName = accountName;
                            account.Password = password;
                            account.Level = level;
                            account.IP = ip;
                            account.IsRight = "请稍后...";
                            account.IsQA = "请稍后...";
                            account.RolePencent = 0;
                            listAccounts.Add(account);
                            //dataTable.Rows.Add(server, accountName, password, level, ip, "请稍后...", "请稍后...", "0", 0);
                        }
                    }
                    catch (Exception)
                    {
                        throw new Exception();
                    }
                }
                reader.Close();
                return listAccounts;
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "ReadFile/读取黑信";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                //service.InsertErrorLog(log);
                return new List<Account>();
            }
        }
        #endregion

        #region 登陆(QQ)
        /// <summary>
        /// 登陆(QQ)
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        private string Login(string userName, string password)
        {
            try
            {
                string message;
                //随机种子
                Random rand = new Random(unchecked((int)(DateTime.Now.Ticks)));
                int seq = rand.Next(1000, 9000);
                //发送数据类型
                string pv = string.Format("VER=1.4&CON=1&CMD=Login&SEQ={0}&UIN={1}&PS={2}&M5=1&LG=0&LC=812822641C978097&GD=5MWX2PF3FOVGTP6B&CKE=", seq, userName, MD5Encryption(password));
                string sret;
                Byte[] pageData;
                SendData(pv, out sret, out pageData);
                //判断是否需要验证码
                if (sret.Contains("&VC="))
                {
                    ImageCode image = new ImageCode();
                    image.shiledImageCode += (DisableImageCode);
                    //判断是否显示验证码
                    if (IsNeed)
                    {
                        ReEnter = true;
                        while (ReEnter)
                        {
                            //弹出窗体显示验证码
                            image.CodeToImage(pageData);
                            image.transImageCode += new ImageCode.TransImageCode(GetImageCode);
                            Invoke(new MethodInvoker(() => image.ShowDialog(this)));

                            //发送验证码验证
                            rand = new Random(unchecked((int)(DateTime.Now.Ticks)));
                            seq = rand.Next(1000, 9000);
                            pv = string.Format("VER=1.4&CON=1&CMD=VERIFYCODE&SEQ={0}&UIN={1}&SID=&XP=C4CA4238A0B92382&SC=2&VC={2}", seq, userName, this.ImageCode);
                            SendData(pv, out sret, out pageData);
                            if (!sret.Contains("&VC="))
                                ReEnter = false;
                        }
                    }
                }
                if (sret.Contains("RES=0&RS=0&HI=60&LI=300"))
                    message = "密码正确";
                else if (sret.Contains("Password error!"))
                    message = "密码错误";
                else if (sret.Contains("&VC="))
                    message = "需要验证码";
                else
                    message = sret.Substring(sret.IndexOf("&RA=", StringComparison.Ordinal) + 4);
                return message;
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "Login/登陆(QQ)";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                //service.InsertErrorLog(log);
                return "该账号频繁登陆,请2分钟后再试" + ex.Message;
            }

        }
        #endregion

        #region 判断账户密码是否正确
        /// <summary>
        /// 判断账户密码是否正确
        /// </summary>
        private void CheckAccount()
        {
            try
            {
                for (int i = CheckAccountIndex; i < gvDetail.RowCount; i++)
                {
                    //刷新数据源
                    gvDetail.RefreshData();
                    gvRoles.RefreshData();
                    Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(i, "IsRight", "Connecting...")));
                    Invoke(new MethodInvoker(() => gvDetail.FocusedRowHandle = i));
                    string account = gvDetail.GetRowCellValue(i, "AccountName").ToString();
                    string password = gvDetail.GetRowCellValue(i, "Password").ToString();
                    //登陆(手机QQ登陆方式)
                    //string LoginResult = Login(account, password);
                    //退出(手机QQ退出方式)
                    //Logout(account);
                    //登陆(网页登陆)
                    string loginResult = LoginWeb(account, password);
                    if (loginResult.Equals("密码正确"))
                    {
                        //判断是否需要查询封号
                        if ((bool)iCheckLeaverBuster.EditValue)
                        {
                            if (CheckLeaverBuster(account))
                            {
                                //封号时间
                                DateTime startTime = Convert.ToDateTime(listResult["StartTime"]);
                                //判断是否是今年封号
                                if (startTime.Month > DateTime.Now.Month)
                                    startTime = startTime.AddYears(-1);
                                else if (startTime.Month == DateTime.Now.Month && startTime.Day > DateTime.Now.Day)
                                    startTime = startTime.AddYears(-1);
                                else if (startTime.Month == DateTime.Now.Month && startTime.Day == DateTime.Now.Day && startTime.Hour > DateTime.Now.Hour)
                                    startTime = startTime.AddYears(-1);
                                else if (startTime.Month == DateTime.Now.Month && startTime.Day == DateTime.Now.Day && startTime.Hour == DateTime.Now.Hour && startTime.Minute > DateTime.Now.Minute)
                                    startTime = startTime.AddYears(-1);
                                //解封时间
                                DateTime endTime = Convert.ToDateTime(startTime).AddHours(double.Parse(PublicClass.RegexString(listResult["Hours"], 1)));
                                TimeSpan span = endTime - DateTime.Now;
                                string leaverBuster = string.Empty;
                                if (span.TotalHours > 24)
                                    leaverBuster = Convert.ToInt16(span.TotalDays) + "天";
                                else if (span.TotalHours < 24)
                                    leaverBuster = Convert.ToInt16(span.TotalHours) + "小时";
                                else if (span.TotalHours < 4)
                                    leaverBuster = Convert.ToInt16(span.Hours) + "小时" + Convert.ToInt16(span.Minutes);
                                else if (span.TotalHours < 1)
                                    leaverBuster = Convert.ToInt16(span.TotalMinutes) + "分";
                                leaverBuster = "剩余解封时间:" + leaverBuster;
                                //判断时间已到但官网未更新
                                if (endTime < DateTime.Now)
                                    leaverBuster = "刚解封,速度上!";
                                Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(i, "LeaverBuster", leaverBuster)));
                                ListAccounts[i].LeaverBuster = leaverBuster;
                            }
                            else
                            {
                                Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(i, "LeaverBuster", "正常")));
                                ListAccounts[i].LeaverBuster = "正常";
                            }
                        }
                        else
                        {
                            Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(i, "LeaverBuster", "您禁止了查询")));
                            ListAccounts[i].LeaverBuster = "您禁止了查询";
                        }


                        //判断是否密保登陆
                        string isQa = CheckQA() ? "是" : "否";
                        Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(i, "IsQA", isQa)));
                        ListAccounts[i].IsQA = isQa;
                        //扫描角色
                        if (isQa.Equals("否") && (bool)iSearchRoles.EditValue)
                        {
                            //Thread threadSearchRole = new Thread(() =>
                            //    {
                            //        SearchRoles(account, i);
                            //    });
                            //threadSearchRole.Start();
                            if (Wait.Equals(string.Empty))
                                SearchRoles(account, i);
                        }

                        //上传账号
                        //UploadAccount accountBean = new UploadAccount();
                        //accountBean.Server = gridView1.GetRowCellValue(i, "Server").ToString();
                        //accountBean.Account = gridView1.GetRowCellValue(i, "Account").ToString();
                        //accountBean.Password = gridView1.GetRowCellValue(i, "Password").ToString();
                        //accountBean.Level = Convert.ToInt32(gridView1.GetRowCellValue(i, "Level"));
                        //accountBean.IP = gridView1.GetRowCellValue(i, "IP").ToString();
                        //accountBean.IsRight = "密码正确";
                        //accountBean.LeaverBuster = gridView1.GetRowCellValue(i, "LeaverBuster").ToString();
                        //accountBean.QA = gridView1.GetRowCellValue(i, "Roles").ToString();
                        //accountBean.IsQA = gridView1.GetRowCellValue(i, "IsQA").ToString();
                        //accountBean.ID = Guid.NewGuid().ToString();
                        //AccountBll.Upload(accountBean);
                    }
                    else
                    {
                        Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(i, "LeaverBuster", "无需查询")));
                    }

                    Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(i, "IsRight", loginResult)));
                    Invoke(new MethodInvoker(() => gvDetail.RowCellStyle += (gridView1_RowStyle)));


                    CheckAccountIndex++;
                }

                //threadCheckAccount.Abort();
                iStart.Enabled = true;
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "CheckAccount/判断账户密码是否正确";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                ////service.InsertErrorLog(log);
            }

        }

        #endregion

        #region  检测封号
        /// <summary>
        /// 检测封号
        /// </summary>
        /// <param name="account">检测账号</param>
        private bool CheckLeaverBuster(string account)
        {
            //查询数据
            string url = "http://app.dnf.qq.com/cgi-bin/act/a20080630fh/showinfo.cgi";
            string pv = url + string.Format("&iUserqq={0}&Submit2=%B2%E9+%D1%AF", account);
            WebClient client = new WebClient();
            Byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(pv);
            Byte[] pageData = client.UploadData(url, "POST", byteArray);
            string sret = System.Text.Encoding.Default.GetString(pageData);
            //判断是否封号
            Lexer lexer = new Lexer(sret);
            Parser parser = new Parser(lexer);
            NodeList htmlNodes = parser.Parse(null);
            //实例化list
            listResult = new Dictionary<string, string>();
            for (int i = 0; i < htmlNodes.Count; i++)
            {
                RecursionHtmlNode(htmlNodes[i], false, account);
            }
            return listResult.Count > 0;
        }

        /// <summary>
        /// 封号结果
        /// </summary>
        Dictionary<string, string> listResult;

        /// <summary>
        /// 遍历html
        /// </summary>
        /// <param name="htmlNode"></param>
        /// <param name="siblingRequired"></param>
        /// <param name="account"></param>
        private void RecursionHtmlNode(INode htmlNode, bool siblingRequired, string account)
        {
            if (htmlNode == null) return;

            //获取节点间的内容
            if (htmlNode.Children != null && htmlNode.Children.Count > 0)
            {
                RecursionHtmlNode(htmlNode.FirstChild, true, account);
                if (htmlNode.FirstChild.GetText().Trim().Equals(account))
                {
                    //封号原因
                    string reason = htmlNode.FirstChild.Parent.Parent.Children[3].FirstChild.GetText();
                    //开始时间
                    string startTime = htmlNode.FirstChild.Parent.Parent.Children[5].FirstChild.GetText();
                    //封号时长
                    string hours = htmlNode.FirstChild.Parent.Parent.Children[7].FirstChild.GetText();

                    listResult.Add("Reason", reason);
                    listResult.Add("StartTime", startTime);
                    listResult.Add("Hours", hours);
                }
            }

            //the sibling nodes
            if (siblingRequired)
            {
                INode sibling = htmlNode.NextSibling;
                while (sibling != null)
                {
                    RecursionHtmlNode(sibling, false, account);
                    sibling = sibling.NextSibling;
                }
            }
        }

        #endregion

        #region 注销
        /// <summary>
        /// 注销账号
        /// </summary>
        /// <param name="UserName"></param>
        private void Logout(string UserName)
        {
            try
            {
                WebClient client = new WebClient();
                Random rand = new Random(unchecked((int)(DateTime.Now.Ticks)));
                int seq = rand.Next(1000, 9000);
                string pv = string.Format("VER=1.4&CON=1&CMD=Logout&SEQ={0}&UIN={1}&SID=&XP=C4CA4238A0B92382", seq, UserName);
                Byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(pv);
                client.UploadData(Host, "POST", byteArray);
                //string sret = System.Text.Encoding.ASCII.GetString(pageData);
                //bool ret = sret.Contains("RES=0");
                //return ret;
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "Logout/注销(QQ)";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                //service.InsertErrorLog(log);
            }

        }
        #endregion

        #region 向服务器发送数据
        /// <summary>
        /// 向服务器发送数据
        /// </summary>
        /// <param name="pv"></param>
        /// <param name="sret"></param>
        /// <param name="pageData"></param>
        private void SendData(string pv, out string sret, out Byte[] pageData)
        {
            WebClient client = new WebClient();
            Byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(pv);
            pageData = client.UploadData(Host, "POST", byteArray);
            sret = System.Text.Encoding.UTF8.GetString(pageData);
        }
        #endregion

        #region 获取输入的验证码
        /// <summary>
        /// 获取输入的验证码
        /// </summary>
        private void GetImageCode(string imageCode)
        {
            if (imageCode == null)
                ImageCode = string.Empty;
            this.ImageCode = imageCode;
        }
        #endregion

        #region 是否显示验证码框

        /// <summary>
        /// 是否显示验证码框
        /// </summary>
        /// <param name="disableImage">全部取消验证码</param>
        /// <param name="cancel">取消一次/重新输入验证码</param>
        private void DisableImageCode(bool disableImage, bool cancel)
        {
            IsNeed = disableImage;
            ReEnter = cancel;
            Wait = string.Empty;
            //iVerCode.EditValue = DisableImage;
        }
        #endregion

        #region MD5加密QQ密码
        /// <summary>
        /// MD5加密QQ密码
        /// </summary>
        /// <param name="toCryString"></param>
        /// <returns></returns>
        public static string MD5Encryption(string toCryString)
        {
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            return BitConverter.ToString(hashmd5.ComputeHash(Encoding.Default.GetBytes(toCryString))).Replace("-", "").ToLower();//asp是小写,把所有字符变小写
        }
        #endregion

        #region 关闭
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iClose_ItemClick(object sender, ItemClickEventArgs e)
        {
            gvAccount.DataSource = null;
        }
        #endregion

        #region 查找
        /// <summary>
        /// 查找
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iFind_ItemClick(object sender, ItemClickEventArgs e)
        {
            gvDetail.OptionsFind.AlwaysVisible = !gvDetail.OptionsFind.AlwaysVisible;
        }
        #endregion

        #region 退出
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (threadCheckAccount != null && threadCheckAccount.IsAlive)
            {
                threadCheckAccount.Abort();
            }
            Environment.Exit(0);
        }
        #endregion

        #region 导出到Excel
        /// <summary>
        /// 导出到Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iExportExcel_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (gvAccount.DataSource == null) return;
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = @"黑信Excel|*.xls";
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName = DateTime.Now.ToShortDateString() + "(" + ListAccounts.Count + ")";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                gvAccount.ExportToXls(saveFileDialog.FileName);
            }

        }
        #endregion

        #region 导出到文本文档
        /// <summary>
        /// 导出到文本文档
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iExportTXT_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (gvAccount.DataSource == null) return;
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = @"黑信txt|*.txt";
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName = DateTime.Now.ToString("MM-dd") + "(" + ListAccounts.Count + ")";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                gvAccount.ExportToText(saveFileDialog.FileName);
            }
        }
        #endregion

        #region 开始扫描正确账号
        /// <summary>
        /// 开始扫描
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iStart_ItemClick(object sender, ItemClickEventArgs e)
        {

            if (ListAccounts == null || ListAccounts.Count == 0) return;
            iStart.Enabled = false;
            iStop.Enabled = true;
            if (threadCheckAccount != null && threadCheckAccount.IsAlive)
            {
                threadCheckAccount.Abort();
            }
            else
            {
                threadCheckAccount = null;
            }
            threadCheckAccount = new Thread(new ThreadStart(CheckAccount));
            if (!threadCheckAccount.IsAlive)
            {
                threadCheckAccount = new Thread(new ThreadStart(CheckAccount));
                threadCheckAccount.Start();
            }
        }
        #endregion

        #region 停止扫描账号
        /// <summary>
        /// 停止扫描账号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iStop_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (ListAccounts == null || ListAccounts.Count == 0) return;
            iStart.Enabled = true;
            if (threadCheckAccount != null && threadCheckAccount.IsAlive)
            {
                threadCheckAccount.Abort();
            }
        }
        #endregion

        #region 设置正确的行背景色/当前行背景色
        /// <summary>
        /// 设置正确的行背景色/当前行背景色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridView1_RowStyle(object sender, RowCellStyleEventArgs e)
        {
            if (e.RowHandle < 0) return;
            //bool isRight = gvDetail.GetRowCellValue(e.RowHandle, "IsRight").ToString().Equals("密码正确");
            //if (isRight)
            //    e.Appearance.BackColor = Color.Green;
            if (e.RowHandle == gvDetail.FocusedRowHandle)
                e.Appearance.BackColor = Color.Goldenrod;
        }
        #endregion

        #region  是否检测封号
        /// <summary>
        /// 是否检测封号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iCheck_EditValueChanged(object sender, EventArgs e)
        {
            IsLeaverBuster = Convert.ToBoolean(iCheckLeaverBuster.EditValue);
        }
        #endregion

        #region 筛选等级
        /// <summary>
        /// 筛选等级
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iLevel_EditValueChanged(object sender, EventArgs e)
        {
            if (ListAccounts != null && ListAccounts.Count > 0)
            {
                int lowLevel = int.Parse(iLevel.EditValue.ToString().Substring(0, iLevel.EditValue.ToString().IndexOf('-')));
                int highLevel = int.Parse(iLevel.EditValue.ToString().Substring(lowLevel.ToString().Length + 1, iLevel.EditValue.ToString().Length - lowLevel.ToString().Length - 1));
                var accounts = ListAccounts.Where(l => l.Level >= lowLevel && l.Level <= highLevel).ToList();
                gvAccount.DataSource = accounts;
            }
        }
        #endregion

        #region 登陆(Web)
        /// <summary>
        /// 登陆(Web)
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private string LoginWeb(string account, string password)
        {
            try
            {
                Random random = new Random();
                HttpHelper helper = new HttpHelper();
                string url = string.Format("http://check.ptlogin2.qq.com/check?uin={0}&appid=1003903&r=", account);
                string imageCode = helper.GetHtml(url);
                string returnText = string.Empty;
                //判断是否需要验证码
                if (GetMiddleText(imageCode, "'", "'").Equals("1"))
                {
                    //imageCode = GetMiddleText(imageCode, "','", "','");
                    ImageCode image = new ImageCode();
                    image.shiledImageCode += (DisableImageCode);
                    //判断是否显示验证码
                    if (IsNeed)
                    {
                        //是否需要重新输入验证码
                        ReEnter = true;
                        while (ReEnter)
                        {

                            //弹出窗体显示验证码
                            image.GetWebImage(account, helper, random);
                            image.transImageCode += new ImageCode.TransImageCode(GetImageCode);
                            Invoke(new MethodInvoker(() => image.ShowDialog(this)));
                            if (ImageCode == null)
                            {
                                ReEnter = false;
                                ImageCode = "FUCK";
                            }
                            //密码加密
                            string passwordEncy = GetPassword(account, password, ImageCode);
                            //登陆
                            url =
                                string.Format(
                                    "http://ptlogin2.qq.com/login?u={0}&p={1}&verifycode={2}&aid=21000127&u1=http%3A%2F%2Fdnf.qq.com%2Fact%2Fa20120905hzgj%2F%3Fadtag%3Dself.web.1&h=1&ptredirect=1&ptlang=2052&daid=8&from_ui=1&dumy=&fp=loginerroralert&action=2-6-6953&mibao_css=&t=1&g=1",
                                    account, passwordEncy, ImageCode);
                            string loginResult = helper.GetHtml(url, HttpHelper.CookieContainer);
                            //判断返回类型
                            switch (GetMiddleText(loginResult, "'", "'"))
                            {
                                case "0":
                                    ReEnter = false;
                                    returnText = "密码正确";
                                    break;
                                case "3":
                                    ReEnter = false;
                                    returnText = "密码错误";
                                    break;
                                case "4":
                                    returnText = "验证码错误";
                                    break;
                                case "19":
                                    ReEnter = false;
                                    returnText = "限制登录";
                                    break;
                                default:
                                    returnText = loginResult;
                                    break;
                            }
                        }
                        return returnText;
                    }
                    else
                    {
                        return "需要验证码";
                    }
                }
                else
                {
                    imageCode = GetMiddleText(imageCode, "','", "','");
                    //密码加密
                    string passwordEncy = GetPassword(account, password, imageCode);
                    //登陆
                    url =
                        string.Format(
                            "http://ptlogin2.qq.com/login?u={0}&p={1}&verifycode={2}&aid=21000127&u1=http%3A%2F%2Fdnf.qq.com%2Fact%2Fa20120905hzgj%2F%3Fadtag%3Dself.web.1&h=1&ptredirect=1&ptlang=2052&daid=8&from_ui=1&dumy=&fp=loginerroralert&action=2-6-6953&mibao_css=&t=1&g=1",
                            account, passwordEncy, imageCode);
                    string loginResult = helper.GetHtml(url, HttpHelper.CookieContainer);
                    switch (GetMiddleText(loginResult, "'", "'"))
                    {
                        case "0":
                            ReEnter = false;
                            returnText = "密码正确";
                            break;
                        case "3":
                            ReEnter = false;
                            returnText = "密码错误";
                            break;
                        case "4":
                            returnText = "验证码错误";
                            break;
                        case "19":
                            ReEnter = false;
                            returnText = "限制登录";
                            break;
                        default:
                            returnText = loginResult;
                            break;
                    }
                    return returnText;
                }
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "LoginWeb/登陆(Web)";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                //service.InsertErrorLog(log);
                return string.Empty;
            }
        }
        #endregion

        #region 密码加密(WEB)
        public string GetPassword(string qqNum, string password, string verifycode)
        {
            //uin为QQ号码转换为16位的16进制  
            int qq;
            int.TryParse(qqNum, out qq);

            qqNum = qq.ToString("x");
            qqNum = qqNum.PadLeft(16, '0');

            String p = Hexchar2Bin(Md5Encryption(password));
            String u = Md5Encryption(p + Hexchar2Bin(qqNum)).ToUpper();
            String v = Md5Encryption(u + verifycode.ToUpper()).ToUpper();
            return v;
        }

        public string Md5Encryption(string input)
        {
            byte[] buffer = MD5.Create().ComputeHash(Encoding.GetEncoding("ISO-8859-1").GetBytes(input));
            return Binl2Hex(buffer);
        }

        public string Binl2Hex(byte[] buffer)
        {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < buffer.Length; i++)
            {
                builder.Append(buffer[i].ToString("x2"));
            }
            return builder.ToString();
        }

        public string Hexchar2Bin(string passWord)
        {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < passWord.Length; i = i + 2)
            {
                builder.Append(Convert.ToChar(Convert.ToInt32(passWord.Substring(i, 2), 16)));
            }
            return builder.ToString();
        }
        #endregion

        #region 根据条件获取服务器信息
        /// <summary>
        /// 根据条件获取服务器信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iGet_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                if (iStartDate.EditValue == null)
                    iStartDate.EditValue = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
                if (iEndDate.EditValue == null)
                    iEndDate.EditValue = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
                if (iServer.EditValue == null)
                    iServer.EditValue = string.Empty;
                DataTable dtAccount = AccountBll.GetAccountByCondition(iStartDate.EditValue.ToString(), iEndDate.EditValue.ToString(),
                                                                       iServer.EditValue.ToString(),
                                                                       iLevel.EditValue.ToString());
                if (dtAccount.Rows.Count > 0)
                {
                    gvAccount.DataSource = null;
                    CheckAccountIndex = 0;
                    gvAccount.DataSource = dtAccount;
                }
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "iGet_ItemClick/根据条件获取服务器信息";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                //service.InsertErrorLog(log);
            }
        }
        #endregion

        #region 获取字符串中间文本
        /// <summary>
        /// 获取字符串中间文本
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="left">左边文本</param>
        /// <param name="right">右边文本</param>
        /// <returns></returns>
        public static string GetMiddleText(string str, string left, string right)
        {
            Regex regex = new Regex(string.Format("(?<={0}).*?(?={1})", left, right), RegexOptions.Compiled);
            Match match = regex.Match(str);
            if (match.Success)
            {
                return match.Value;
            }
            return string.Empty;
        }
        #endregion

        #region 检查是否是密保登陆
        /// <summary>
        /// 检查是否是密保登陆
        /// </summary>
        /// <returns></returns>
        private bool CheckQA()
        {
            HttpHelper helper = new HttpHelper();
            const string url = "http://aq.qq.com/cn2/safe_service/my_game_prot";
            string resultAq = helper.GetHtml(url, HttpHelper.CookieContainer);
            //string regex = @"(?s)<li\s+class=""ge[1|2|3]"">.*?</li>";
            const string regex = @"(?s)<ul\s+onclick=""showGameItem\(\d\);"">.*?</ul>";
            MatchCollection match = Regex.Matches(resultAq, regex);
            return match.Cast<Match>().Any(m => m.Value.Contains("地下城与勇士") && m.Value.Contains("已开通"));
        }
        #endregion

        #region 查询角色
        /// <summary>
        /// 查询角色
        /// </summary>
        private void SearchRoles(string account, int rowHandle)
        {
            try
            {
                Wait = "y";
                lock (Wait)
                {
                    List<string[]> listServer = ListServer();
                    HttpHelper helper = new HttpHelper();
                    BindingList<Role> listRole = new BindingList<Role>();
                    for (int j = 0; j < listServer.Count; j++)
                    {
                        //扫描角色进度百分比
                        int pencent = (Convert.ToInt32(Convert.ToDouble(j + 1) / Convert.ToDouble(listServer.Count) * 100));
                        //百分比赋值到进度条
                        Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(rowHandle, "RolePencent", pencent)));
                        ListAccounts[rowHandle].RolePencent = pencent;
                        string url = string.Format("http://apps.game.qq.com/comm-cgi-bin/content_admin/activity_center/query_role.cgi?game=dnf&area={0}&callback=&_=", listServer[j][1]);
                        string roleStr = helper.GetHtml(url, HttpHelper.CookieContainer);
                        if (!roleStr.Contains("msg=0") && !roleStr.Contains("msg=&"))
                        {
                            int start = roleStr.IndexOf("msg=") + 4;
                            int end = roleStr.IndexOf("|");
                            if (start < 0 || end < 0)
                                continue;
                            int index = Convert.ToInt16(roleStr.Substring(start, end - start));
                            for (int k = 0; k < index; k++)
                            {

                                //Role role = new Role();
                                //role = StringToBean(roleStr, out roleStr, account, j);
                                //((ListAccounts.Where(c => c.AccountName.Equals(account))).First()).listRole.Add(StringToBean(roleStr, out roleStr, account, j));
                                listRole.Add(StringToBean(roleStr, out roleStr, account, j));
                            }
                        }
                    }
                    //按照大区,等级排序
                    //listRole = listRole.OrderByDescending(c => c.RoleServer).ThenByDescending(c => c.RoleLevel) as BindingList<Role>;
                    if (ListAccounts[rowHandle].listRole == null)
                        ListAccounts[rowHandle].listRole = new BindingList<Role>();
                    ListAccounts[rowHandle].listRole = listRole;
                    Invoke(new MethodInvoker(() => gvDetail.SetRowCellValue(rowHandle, "Level", ListAccounts[rowHandle].listRole.OrderByDescending(c => c.RoleLevel).First().RoleLevel)));
                }
                //刷新数据源
                gvDetail.RefreshData();
                gvRoles.RefreshData();
                //Invoke(new MethodInvoker(() => gvAccount.DataSource = ListAccounts));
                Wait = string.Empty;
            }
            catch (Exception ex)
            {
                SystemLogModel log = new SystemLogModel();
                log.ID = Guid.NewGuid().ToString();
                log.Project = "DnfAccountScan";
                log.MethodName = "SearchRoles/查询角色";
                log.ExceptionType = ex.GetType().ToString();
                log.Exceptions = ex.Message;
                //service.InsertErrorLog(log);
            }
        }
        #endregion

        #region 角色类型
        /// <summary>
        /// 角色类型
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        private string SwitchRole(int code)
        {
            switch (code)
            {
                case 0:
                    return "鬼剑士";
                case 1:
                    return "格斗家(女)";
                case 2:
                    return "神枪手(男)";
                case 3:
                    return "魔法师(女)";
                case 4:
                    return "圣职者";
                case 5:
                    return "神枪手(女)";
                case 6:
                    return "暗夜使者";
                case 7:
                    return "格斗家(男)";
                case 8:
                    return "魔法师(男)";
                case 9:
                case 10:
                    return "缔造者";
                default:
                    return "未知";
            }
        }
        #endregion

        #region 服务器列表
        /// <summary>
        /// 服务器列表
        /// </summary>
        /// <returns></returns>
        private List<string[]> ListServer()
        {
            List<string[]> listServer = new List<string[]>();
            listServer.Add(new[] { "广东1区", "1" });
            listServer.Add(new[] { "广东2区", "15" });
            listServer.Add(new[] { "广东3区", "22" });
            listServer.Add(new[] { "广东4区", "45" });
            listServer.Add(new[] { "广东5区", "52" });
            listServer.Add(new[] { "广东6区", "65" });
            listServer.Add(new[] { "广东7区", "71" });
            listServer.Add(new[] { "广东8区", "81" });
            listServer.Add(new[] { "广东9区", "89" });
            listServer.Add(new[] { "广东10区", "98" });
            listServer.Add(new[] { "广东11区", "105" });
            listServer.Add(new[] { "广东12区", "126" });
            listServer.Add(new[] { "福建1区", "14" });
            listServer.Add(new[] { "福建2区", "44" });
            listServer.Add(new[] { "福建3区", "80" });
            listServer.Add(new[] { "福建4区", "113" });
            listServer.Add(new[] { "浙江1区", "11" });
            listServer.Add(new[] { "浙江2区", "21" });
            listServer.Add(new[] { "浙江3区", "55" });
            listServer.Add(new[] { "浙江4区", "84" });
            listServer.Add(new[] { "浙江5区", "111" });
            listServer.Add(new[] { "浙江6区", "116" });
            listServer.Add(new[] { "浙江7区", "129" });
            listServer.Add(new[] { "北京1区", "2" });
            listServer.Add(new[] { "北京2区", "35" });
            listServer.Add(new[] { "北京3区", "72" });
            listServer.Add(new[] { "北京4区", "130" });
            listServer.Add(new[] { "上海1区", "3" });
            listServer.Add(new[] { "上海2区", "16" });
            listServer.Add(new[] { "上海3区", "36" });
            listServer.Add(new[] { "上海4区", "93" });
            listServer.Add(new[] { "上海5区", "114" });
            listServer.Add(new[] { "四川1区", "4" });
            listServer.Add(new[] { "四川2区", "26" });
            listServer.Add(new[] { "四川3区", "56" });
            listServer.Add(new[] { "四川4区", "70" });
            listServer.Add(new[] { "四川5区", "82" });
            listServer.Add(new[] { "四川6区", "107" });
            listServer.Add(new[] { "湖南1区", "5" });
            listServer.Add(new[] { "湖南2区", "25" });
            listServer.Add(new[] { "湖南3区", "50" });
            listServer.Add(new[] { "湖南4区", "66" });
            listServer.Add(new[] { "湖南5区", "74" });
            listServer.Add(new[] { "湖南6区", "85" });
            listServer.Add(new[] { "湖南7区", "117" });
            listServer.Add(new[] { "山东1区", "6" });
            listServer.Add(new[] { "山东2区", "37" });
            listServer.Add(new[] { "山东3区", "59" });
            listServer.Add(new[] { "山东4区", "75" });
            listServer.Add(new[] { "山东5区", "78" });
            listServer.Add(new[] { "山东6区", "106" });
            listServer.Add(new[] { "山东7区", "131" });
            listServer.Add(new[] { "江苏1区", "7" });
            listServer.Add(new[] { "江苏2区", "20" });
            listServer.Add(new[] { "江苏3区", "41" });
            listServer.Add(new[] { "江苏4区", "53" });
            listServer.Add(new[] { "江苏5区", "79" });
            listServer.Add(new[] { "江苏6区", "90" });
            listServer.Add(new[] { "江苏7区", "101" });
            listServer.Add(new[] { "江苏8区", "109" });
            listServer.Add(new[] { "湖北1区", "9" });
            listServer.Add(new[] { "湖北2区", "24" });
            listServer.Add(new[] { "湖北3区", "48" });
            listServer.Add(new[] { "湖北4区", "68" });
            listServer.Add(new[] { "湖北5区", "76" });
            listServer.Add(new[] { "湖北6区", "94" });
            listServer.Add(new[] { "湖北7区", "115" });
            listServer.Add(new[] { "湖北8区", "127" });
            listServer.Add(new[] { "华北1区", "10" });
            listServer.Add(new[] { "华北2区", "19" });
            listServer.Add(new[] { "华北3区", "54" });
            listServer.Add(new[] { "华北4区", "87" });
            listServer.Add(new[] { "西北1区", "12" });
            listServer.Add(new[] { "西北2区", "46" });
            listServer.Add(new[] { "西北3区", "86" });
            listServer.Add(new[] { "东北1区", "13" });
            listServer.Add(new[] { "东北2区", "18" });
            listServer.Add(new[] { "东北3区", "23" });
            listServer.Add(new[] { "东北4区", "83" });
            listServer.Add(new[] { "东北5区", "91" });
            listServer.Add(new[] { "东北6区", "97" });
            listServer.Add(new[] { "东北7区", "128" });
            listServer.Add(new[] { "西南1区", "17" });
            listServer.Add(new[] { "西南2区", "49" });
            listServer.Add(new[] { "西南3区", "92" });
            listServer.Add(new[] { "河南1区", "27" });
            listServer.Add(new[] { "河南2区", "43" });
            listServer.Add(new[] { "河南3区", "57" });
            listServer.Add(new[] { "河南4区", "69" });
            listServer.Add(new[] { "河南5区", "77" });
            listServer.Add(new[] { "河南6区", "103" });
            listServer.Add(new[] { "广西1区", "28" });
            listServer.Add(new[] { "广西2区", "64" });
            listServer.Add(new[] { "广西3区", "88" });
            listServer.Add(new[] { "广西4区", "112" });
            listServer.Add(new[] { "广西5区", "133" });
            listServer.Add(new[] { "江西1区", "29" });
            listServer.Add(new[] { "江西2区", "62" });
            listServer.Add(new[] { "江西3区", "96" });
            listServer.Add(new[] { "安徽1区", "30" });
            listServer.Add(new[] { "安徽2区", "58" });
            listServer.Add(new[] { "安徽3区", "104" });
            listServer.Add(new[] { "辽宁1区", "31" });
            listServer.Add(new[] { "辽宁2区", "47" });
            listServer.Add(new[] { "辽宁3区", "61" });
            listServer.Add(new[] { "山西1区", "32" });
            listServer.Add(new[] { "山西2区", "95" });
            listServer.Add(new[] { "陕西1区", "33" });
            listServer.Add(new[] { "陕西2区", "63" });
            listServer.Add(new[] { "陕西3区", "119" });
            listServer.Add(new[] { "广州1区", "34" });
            listServer.Add(new[] { "广州2区", "102" });
            listServer.Add(new[] { "河北1区", "38" });
            listServer.Add(new[] { "河北2区", "67" });
            listServer.Add(new[] { "河北3区", "110" });
            listServer.Add(new[] { "河北4区", "118" });
            listServer.Add(new[] { "河北5区", "132" });
            listServer.Add(new[] { "重庆1区", "39" });
            listServer.Add(new[] { "重庆2区", "73" });
            listServer.Add(new[] { "黑龙江1区", "40" });
            listServer.Add(new[] { "黑龙江2区", "51" });
            listServer.Add(new[] { "黑龙江3区", "108" });
            listServer.Add(new[] { "吉林1区", "42" });
            listServer.Add(new[] { "吉林2区", "60" });
            listServer.Add(new[] { "云南1区", "120" });
            listServer.Add(new[] { "贵州1区", "122" });
            listServer.Add(new[] { "云贵1区", "124" });
            listServer.Add(new[] { "天津一区", "121" });
            listServer.Add(new[] { "新疆一区", "123" });
            listServer.Add(new[] { "内蒙古地区", "125" });
            listServer.Add(new[] { "体验服", "99" });
            listServer.Add(new[] { "PK服", "100" });
            return listServer;
        }
        #endregion

        #region 服务器返回的数据转换为RoleBean
        /// <summary>
        /// 服务器返回的数据转换为RoleBean
        /// </summary>
        /// <param name="roleStr"></param>
        /// <param name="roleStr2"></param>
        /// <param name="account"></param>
        /// <param name="server"></param>
        /// <returns></returns>
        private Role StringToBean(string roleStr, out string roleStr2, string account, int server)
        {
            Role role = new Role();
            roleStr = roleStr.Remove(0, roleStr.IndexOf('|') + 1);
            role.RoleId = roleStr.Substring(0, roleStr.IndexOf(' '));
            roleStr = roleStr.Remove(0, role.RoleId.Length).TrimStart();
            role.RoleName = roleStr.Substring(0, roleStr.IndexOf(' '));
            roleStr = roleStr.Remove(0, role.RoleName.Length).TrimStart();
            role.RoleType = roleStr.Substring(0, roleStr.IndexOf(' '));
            roleStr = roleStr.Remove(0, role.RoleType.Length).TrimStart();
            role.RoleLevel = Convert.ToInt32(roleStr.Substring(0, roleStr.IndexOf('|')));
            roleStr = roleStr.Remove(0, role.RoleLevel.ToString().Length).TrimStart();
            roleStr2 = roleStr;
            role.RoleAccount = account;
            role.RoleName = HttpUtility.UrlDecode(role.RoleName);
            role.RoleType = SwitchRole(int.Parse(role.RoleType));
            role.RoleServer = ListServer()[server][0];
            return role;
        }
        #endregion
    }
}